/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package cn.eeepay.framework.util;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 */
public class ResultModel extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public ResultModel() {
		put("code", 200);
		put("msg", "success");
		put("status", true);
	}
	
	public static ResultModel error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}
	
	public static ResultModel error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}
	
	public static ResultModel error(int code, String msg) {
		ResultModel r = new ResultModel();
		r.put("code", code);
		r.put("msg", msg);
		r.put("status", false);
		return r;
	}

	public static ResultModel ok(String msg) {
		ResultModel r = new ResultModel();
		r.put("msg", msg);
		r.put("status", true);
		return r;
	}
	
	public static ResultModel ok(Map<String, Object> map) {
		ResultModel r = new ResultModel();
		r.putAll(map);
		return r;
	}
	
	public static ResultModel ok() {
		return new ResultModel();
	}

	public ResultModel put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}
